<?php

/**
 * 列表查询分页数据拼装
 */
if (!function_exists('pagination')) {
	function pagination($lists, $request)
	{
		//利用scope查询
		if (array_key_exists('data', $request)) {
			if (!empty($request['data'] && is_array($request['data']))) {
				foreach ($request['data'] as $key => $val) {
					if (!empty($val)) {
						$lists = $lists->{$key}($val);
					}
				}
			}
		}

		//分页拼装
		$lists = $lists->paginate($request['limit'])->toArray();

		$records = array();
		$records['code'] = 0;
		$records['msg'] = '';
		$records['count'] = $lists['total'];
		$records['data'] = $lists['data'];

		return $records;
	}
}